<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>I/O Pin Handling</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="kvaser.gif"/></td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('page_user_guide_kviopin.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">I/O Pin Handling </div>  </div>
</div><!--header-->
<div class="contents">
<div class="toc"><h3>Table of Contents</h3>
<ul><li class="level1"><a href="#section_user_guide_kviopin_init">Initialize</a></li>
<li class="level1"><a href="#section_user_guide_kviopin_info">Pin information</a></li>
<li class="level1"><a href="#section_user_guide_kviopin_type">IO pin types</a><ul><li class="level2"><a href="#section_user_guide_kviopin_type_analog">Analog Pins</a></li>
<li class="level2"><a href="#section_user_guide_kviopin_type_digital">Digital Pins</a></li>
<li class="level2"><a href="#section_user_guide_kviopin_type_relay">Relay Pins</a></li>
</ul>
</li>
</ul>
</div>
<div class="textblock"><h1><a class="anchor" id="section_user_guide_kviopin_init"></a>
Initialize</h1>
<p>Some Kvaser products feature I/O pins that can be used in real-time applications using our API dedicated to <a class="el" href="group__kv__io.html">I/O Pin Handling</a>. This API is initialized by confirming the I/O pin configuration, see <a class="el" href="group__kv__io.html#gaa50d734d29488bea72f5d3808835d7d9">kvIoConfirmConfig</a>. Before the configuration is confirmed the user can only retrieve information about the pins, such as the total number of pins using <a class="el" href="group__kv__io.html#ga0194114ea5bfcbf770d938b613ba87e6">kvIoGetNumberOfPins</a>, and after the configuration has been confirmed the user may set or read any values of the I/O pins.</p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> channel_nbr;</div><div class="line"><span class="keywordtype">int</span> nbr_of_pins;</div><div class="line"><span class="keywordtype">int</span> hnd;</div><div class="line"><a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7">canStatus</a> status;</div><div class="line"></div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"></div><div class="line">canInitializeLibrary();</div><div class="line"></div><div class="line">hnd = <a class="code" href="group___c_a_n.html#gac377d182232fb4ec2fed881c2b9ab300">canOpenChannel</a>(channel_nbr, 0);</div><div class="line"></div><div class="line"><span class="keywordflow">if</span> ( hnd &lt; 0 ) {</div><div class="line">  printf(<span class="stringliteral">&quot;Failed to open channel\n&quot;</span>);</div><div class="line">  <span class="keywordflow">return</span>;</div><div class="line">}</div><div class="line"></div><div class="line">status = <a class="code" href="group__kv__io.html#ga0194114ea5bfcbf770d938b613ba87e6">kvIoGetNumberOfPins</a>(hnd, &amp;nbr_of_pins);</div><div class="line"></div><div class="line"><span class="keywordflow">if</span> ( status != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> ) {</div><div class="line">  printf(<span class="stringliteral">&quot;Failed to get the number of pins (%d)\n&quot;</span>, status);</div><div class="line">  <a class="code" href="group___c_a_n.html#ga49525373a4d08d93c651ec10f79dd36b">canClose</a>(hnd);</div><div class="line">  <span class="keywordflow">return</span>;</div><div class="line">}</div><div class="line"></div><div class="line">printf(<span class="stringliteral">&quot;Found %d pins.\n&quot;</span>, nbr_of_pins);</div><div class="line"></div><div class="line">status = <a class="code" href="group__kv__io.html#gaa50d734d29488bea72f5d3808835d7d9">kvIoConfirmConfig</a>(hnd);</div><div class="line"></div><div class="line"><span class="keywordflow">if</span> ( status != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> ) {</div><div class="line">  printf(<span class="stringliteral">&quot;Failed to confirm the configuration (%d)\n&quot;</span>, status);</div><div class="line">  <a class="code" href="group___c_a_n.html#ga49525373a4d08d93c651ec10f79dd36b">canClose</a>(hnd);</div><div class="line">  <span class="keywordflow">return</span>;</div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// Now we can read and set values of the I/O pins.</span></div></div><!-- fragment --><h1><a class="anchor" id="section_user_guide_kviopin_info"></a>
Pin information</h1>
<p>Pins are identified by their pin number, which is a number from zero up to, but not including, the value returned by <a class="el" href="group__kv__io.html#ga0194114ea5bfcbf770d938b613ba87e6">kvIoGetNumberOfPins()</a>. Using the pin number the specific properties of any pin is retrieved using <a class="el" href="group__kv__io.html#ga851cb68946bf38686a065fccf11d6b42">kvIoPinGetInfo</a> and modified using <a class="el" href="group__kv__io.html#ga88dda296acccff6acbc979a94b961188">kvIoPinSetInfo</a>. See <a class="el" href="canlib_8h.html#kvIO_INFO_GET_xxx">kvIO_INFO_GET_xxx</a> and <a class="el" href="canlib_8h.html#kvIO_INFO_SET_xxx">kvIO_INFO_SET_xxx</a> to learn what properties can be read and modified.</p>
<div class="fragment"><div class="line"><span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i;</div><div class="line"><span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> nbr_of_pins;</div><div class="line"></div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line"></div><div class="line"><span class="comment">// Getting some information from the pins</span></div><div class="line"></div><div class="line">for ( i = 0; i &lt; nbr_of_pins; i++ ) {</div><div class="line">  printf(<span class="stringliteral">&quot;Pin %u:\n&quot;</span>, i);</div><div class="line"></div><div class="line">  status = <a class="code" href="group__kv__io.html#ga851cb68946bf38686a065fccf11d6b42">kvIoPinGetInfo</a>(hnd, i, <a class="code" href="canlib_8h.html#aa35b3f04d717c654cec0a4f0468ebf84">kvIO_INFO_GET_DIRECTION</a>, &amp;data, <span class="keyword">sizeof</span>(data));</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( status == <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> ) {</div><div class="line">    printf(<span class="stringliteral">&quot;   direction: %s\n&quot;</span>, ( data == <a class="code" href="canlib_8h.html#a9e269996cbfabef79b05627e60bfb0f4">kvIO_PIN_DIRECTION_IN</a> ? <span class="stringliteral">&quot;In&quot;</span> : <span class="stringliteral">&quot;Out&quot;</span> ));</div><div class="line">  } <span class="keywordflow">else</span> {</div><div class="line">    printf(<span class="stringliteral">&quot;   direction: error\n&quot;</span>);</div><div class="line">  }</div><div class="line"></div><div class="line">  status = <a class="code" href="group__kv__io.html#ga851cb68946bf38686a065fccf11d6b42">kvIoPinGetInfo</a>(hnd, i, <a class="code" href="canlib_8h.html#aca429207da12ba1659499a6793ce18b4">kvIO_INFO_GET_PIN_TYPE</a>, &amp;data, <span class="keyword">sizeof</span>(data));</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( status == <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> ) {</div><div class="line">    printf(<span class="stringliteral">&quot;   Pin type:  %s\n&quot;</span>,</div><div class="line">      ( data == <a class="code" href="canlib_8h.html#a6c6338d248a8b47f09b4d53041b9f167">kvIO_PIN_TYPE_DIGITAL</a> ? <span class="stringliteral">&quot;Digital&quot;</span> : \</div><div class="line">      ( data == <a class="code" href="canlib_8h.html#abb5238d0a6c1de0fb683de27a9ee8a9c">kvIO_PIN_TYPE_RELAY</a>   ? <span class="stringliteral">&quot;Relay&quot;</span>   : \</div><div class="line">      ( data == <a class="code" href="canlib_8h.html#a757a9a7296413cb3187b78775553317d">kvIO_PIN_TYPE_ANALOG</a>  ? <span class="stringliteral">&quot;Analog&quot;</span>  : \</div><div class="line">                                        <span class="stringliteral">&quot;Unknown&quot;</span>)</div><div class="line">      )));</div><div class="line">  } <span class="keywordflow">else</span> {</div><div class="line">    printf(<span class="stringliteral">&quot;   Pin type: error\n&quot;</span>);</div><div class="line">  }</div><div class="line"></div><div class="line">}</div></div><!-- fragment --><h1><a class="anchor" id="section_user_guide_kviopin_type"></a>
IO pin types</h1>
<p>There are currently three types of pins that is supported by our API dedicated to <a class="el" href="group__kv__io.html">I/O Pin Handling</a>. These include analog, digital and relay pins. To learn what pin type a given pin is, the argument <a class="el" href="canlib_8h.html#aca429207da12ba1659499a6793ce18b4">kvIO_INFO_GET_PIN_TYPE</a> is used when calling <a class="el" href="group__kv__io.html#ga851cb68946bf38686a065fccf11d6b42">kvIoPinGetInfo</a>. See <a class="el" href="canlib_8h.html#kvIO_PIN_TYPE_xxx">kvIO_PIN_TYPE_xxx</a> to see what type each value represents.</p>
<h2><a class="anchor" id="section_user_guide_kviopin_type_analog"></a>
Analog Pins</h2>
<p>The analog pins are represented by multiple bits, the number of bits can be retrieved by using <a class="el" href="group__kv__io.html#ga851cb68946bf38686a065fccf11d6b42">kvIoPinGetInfo</a> with <a class="el" href="canlib_8h.html#ac32b2fe0d62c2ca63c4a15994d65f725">kvIO_INFO_GET_NUMBER_OF_BITS</a> as an argument. The value of an analog pin is within in the interval given by <a class="el" href="canlib_8h.html#aa4208430dc0a552a3a66d2103bde6c02">kvIO_INFO_GET_RANGE_MIN</a> and <a class="el" href="canlib_8h.html#a3ef294dd72816343f9bab9dc9c9dab39">kvIO_INFO_GET_RANGE_MAX</a>. The analog input pin has two configurable properties, namely the low pass filter order and the hysteresis. See <a class="el" href="canlib_8h.html#af8dd482621b791755305bcbe70b4caaa">kvIO_INFO_SET_AI_LP_FILTER_ORDER</a> and <a class="el" href="canlib_8h.html#a0d5515549989d5f70a258f159aa8fef0">kvIO_INFO_SET_AI_HYSTERESIS</a> to learn about these properties. Pins are read and set using <a class="el" href="group__kv__io.html#ga38a215ebc548b0d201fe805c5a8b3797">kvIoPinSetAnalog</a> and <a class="el" href="group__kv__io.html#ga209b5932e8abf5e085c778d0dcac78ab">kvIoPinGetAnalog</a> respectively. To read the latest set output of an output pin the function <a class="el" href="group__kv__io.html#ga78dd0cebc929d0c0d2b801943c6b0ddc">kvIoPinGetOutputAnalog</a> is used.</p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> pin_type;</div><div class="line"><span class="keywordtype">int</span> direction;</div><div class="line"><span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> pin;</div><div class="line"></div><div class="line">.</div><div class="line">.</div><div class="line">.</div><div class="line">if ( pin_type == <a class="code" href="canlib_8h.html#a757a9a7296413cb3187b78775553317d">kvIO_PIN_TYPE_ANALOG</a> ) {</div><div class="line">  <span class="keywordtype">float</span> data = (float) 0.2;</div><div class="line">  <span class="keywordtype">int</span> lp_fo = 3</div><div class="line"></div><div class="line">  <span class="comment">// Setting the hysteresis to 0.2</span></div><div class="line">  status = <a class="code" href="group__kv__io.html#ga88dda296acccff6acbc979a94b961188">kvIoPinSetInfo</a>(hnd, pin, <a class="code" href="canlib_8h.html#a0d5515549989d5f70a258f159aa8fef0">kvIO_INFO_SET_AI_HYSTERESIS</a>, &amp;data, <span class="keyword">sizeof</span>(data));</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( status != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> )</div><div class="line">    printf(<span class="stringliteral">&quot;Failed to set hysteresis of pin %u\n&quot;</span>, pin);</div><div class="line"></div><div class="line">  <span class="comment">// Setting the low pass filter to 3</span></div><div class="line">  status = <a class="code" href="group__kv__io.html#ga88dda296acccff6acbc979a94b961188">kvIoPinSetInfo</a>(hnd, pin, <a class="code" href="canlib_8h.html#af8dd482621b791755305bcbe70b4caaa">kvIO_INFO_SET_AI_LP_FILTER_ORDER</a>, &amp;lp_fo, <span class="keyword">sizeof</span>(lp_fo));</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( status != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> )</div><div class="line">    printf(<span class="stringliteral">&quot;Failed to set low pass filter order of pin %u\n&quot;</span>, pin);</div><div class="line"></div><div class="line">  .</div><div class="line">  .</div><div class="line">  .</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( direction == <a class="code" href="canlib_8h.html#a32aebdbba25ff32662f8112e222af0a4">kvIO_PIN_DIRECTION_OUT</a> ) {</div><div class="line">    <span class="comment">// Writing 4.0 Volts to the analog output</span></div><div class="line">    status = <a class="code" href="group__kv__io.html#ga38a215ebc548b0d201fe805c5a8b3797">kvIoPinSetAnalog</a>(hnd, pin, (<span class="keywordtype">float</span>) 4.0);</div><div class="line">  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( direction == <a class="code" href="canlib_8h.html#a9e269996cbfabef79b05627e60bfb0f4">kvIO_PIN_DIRECTION_IN</a> ) {</div><div class="line">    <span class="comment">// Reading the voltage level on the analog input</span></div><div class="line">    status = <a class="code" href="group__kv__io.html#ga209b5932e8abf5e085c778d0dcac78ab">kvIoPinGetAnalog</a>(hnd, pin, &amp;data);</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> ( status == <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> )</div><div class="line">      printf(<span class="stringliteral">&quot;The voltage level is at %f on pin %u\n&quot;</span>, data, pin);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( status != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> )</div><div class="line">    printf(<span class="stringliteral">&quot;Failed to set/get voltage level on pin %u\n&quot;</span>, pin);</div><div class="line"></div><div class="line">}</div></div><!-- fragment --><h2><a class="anchor" id="section_user_guide_kviopin_type_digital"></a>
Digital Pins</h2>
<p>The digital pins have two configurable properties, namely the low-to-high and the high-to-low filter time. See <a class="el" href="canlib_8h.html#a13fe255e44c25ff63a4bb2271d816606">kvIO_INFO_SET_DI_HIGH_LOW_FILTER</a> and <a class="el" href="canlib_8h.html#afa7572ee9ed7b364ed70002d3101dfdd">kvIO_INFO_SET_DI_LOW_HIGH_FILTER</a> to learn about these properties. Pins are read and set using <a class="el" href="group__kv__io.html#gad5a1f760ce49861c5970764024a732c7">kvIoPinSetDigital</a> and <a class="el" href="group__kv__io.html#gaa5699336bbf78ddbe430dee8658ca7b3">kvIoPinGetDigital</a> respectively. To read the latest set output of an output pin the function <a class="el" href="group__kv__io.html#gaaa8b56dd310525951aea002efa0d55ef">kvIoPinGetOutputDigital</a> is used.</p>
<div class="fragment"><div class="line"><span class="keywordflow">if</span> ( pin_type == <a class="code" href="canlib_8h.html#a6c6338d248a8b47f09b4d53041b9f167">kvIO_PIN_TYPE_DIGITAL</a> ) {</div><div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> data = 500;</div><div class="line"></div><div class="line">  <span class="comment">// Setting the high-to-low filter time to 500 µs</span></div><div class="line">  status = <a class="code" href="group__kv__io.html#ga88dda296acccff6acbc979a94b961188">kvIoPinSetInfo</a>(hnd, pin, <a class="code" href="canlib_8h.html#a13fe255e44c25ff63a4bb2271d816606">kvIO_INFO_SET_DI_HIGH_LOW_FILTER</a>, &amp;data, <span class="keyword">sizeof</span>(data));</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( status != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> )</div><div class="line">    printf(<span class="stringliteral">&quot;Failed to set high-to-low filter time of pin %u\n&quot;</span>, pin);</div><div class="line"></div><div class="line">  <span class="comment">// Setting the low-to-high filter time to 500 µs</span></div><div class="line">  status = <a class="code" href="group__kv__io.html#ga88dda296acccff6acbc979a94b961188">kvIoPinSetInfo</a>(hnd, pin, <a class="code" href="canlib_8h.html#afa7572ee9ed7b364ed70002d3101dfdd">kvIO_INFO_SET_DI_LOW_HIGH_FILTER</a>, &amp;data, <span class="keyword">sizeof</span>(data));</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( status != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> )</div><div class="line">    printf(<span class="stringliteral">&quot;Failed to set low-to-high filter time of pin %u\n&quot;</span>, pin);</div><div class="line"></div><div class="line">  .</div><div class="line">  .</div><div class="line">  .</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( direction == <a class="code" href="canlib_8h.html#a32aebdbba25ff32662f8112e222af0a4">kvIO_PIN_DIRECTION_OUT</a> ) {</div><div class="line">    <span class="comment">// Writing 1 to the digital output</span></div><div class="line">    status = <a class="code" href="group__kv__io.html#gad5a1f760ce49861c5970764024a732c7">kvIoPinSetDigital</a>(hnd, pin, 1);</div><div class="line">  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( direction == <a class="code" href="canlib_8h.html#a9e269996cbfabef79b05627e60bfb0f4">kvIO_PIN_DIRECTION_IN</a> ) {</div><div class="line">    status = <a class="code" href="group__kv__io.html#gaa5699336bbf78ddbe430dee8658ca7b3">kvIoPinGetDigital</a>(hnd, pin, &amp;data);</div><div class="line"></div><div class="line">    <span class="keywordflow">if</span> ( status == <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> )</div><div class="line">      printf(<span class="stringliteral">&quot;The digital input pin %u is %d\n&quot;</span>, pin, data);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( status != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> )</div><div class="line">    printf(<span class="stringliteral">&quot;Failed to set/get voltage level on digital pin %u\n&quot;</span>, pin);</div><div class="line"></div><div class="line">}</div></div><!-- fragment --><h2><a class="anchor" id="section_user_guide_kviopin_type_relay"></a>
Relay Pins</h2>
<p>The relay pins have no configurable properties. All of these pins are considered as outputs. Pins are set using <a class="el" href="group__kv__io.html#gabb4bfa9d8f76d64065e03a9c95b7dace">kvIoPinSetRelay</a> and the status of them, whether they are activated or not, is read using <a class="el" href="group__kv__io.html#ga26aaef6002a588a2ee56bdfc89a703df">kvIoPinGetOutputRelay</a>.</p>
<div class="fragment"><div class="line"><span class="keywordflow">if</span> ( pin_type == <a class="code" href="canlib_8h.html#abb5238d0a6c1de0fb683de27a9ee8a9c">kvIO_PIN_TYPE_RELAY</a> ) {</div><div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> data;</div><div class="line"></div><div class="line">  status = <a class="code" href="group__kv__io.html#ga26aaef6002a588a2ee56bdfc89a703df">kvIoPinGetOutputRelay</a>(hnd, pin, &amp;data);</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( status == <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> ) {</div><div class="line">    printf(<span class="stringliteral">&quot;Status of relay pin %u: %u\n&quot;</span>, pin, data);</div><div class="line"></div><div class="line">    data = !data; <span class="comment">// Toggle the relay pin</span></div><div class="line"></div><div class="line">    status = <a class="code" href="group__kv__io.html#gabb4bfa9d8f76d64065e03a9c95b7dace">kvIoPinSetRelay</a>(hnd, pin, data);</div><div class="line">  }</div><div class="line"></div><div class="line">  <span class="keywordflow">if</span> ( status != <a class="code" href="canstat_8h.html#a52b5e5c71832b0bd3c6a5b1fd48583e7a49743d0d438957118b9c6af2e831b209">canOK</a> )</div><div class="line">    printf(<span class="stringliteral">&quot;Failed to set value of relay pin %u.\n&quot;</span>, pin);</div><div class="line"></div><div class="line">}</div></div><!-- fragment --> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- HTML footer for doxygen 1.8.13-->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="page_canlib.html">CAN bus API (CANlib)</a></li>
    <li class="footer"> (canlib 5.38) Tue Feb 15 2022</li>
  </ul>
</div>
</body>
</html>
